package com.dj.shop.service.impl;

import com.dj.shop.mapper.GoodsClassMapper;
import com.dj.shop.mapper.GoodsMapper;
import com.dj.shop.model.Goods;
import com.dj.shop.model.GoodsClass;
import com.dj.shop.service.GoodsService;
import com.dj.shop.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Author: zhaoyu
 * @CreateDate: 2019/2/25 16:36
 * @UpdateUser:
 * @UpdateDate:
 * @UpdateRemark:
 */
@Service
public class GoodsServiceImpl implements GoodsService {
    /**
     * 日志
     */
    private final Logger logger = LoggerFactory.getLogger(GoodsServiceImpl.class);

    @Autowired
    private GoodsClassMapper goodsClassMapper;

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public int addGoodsClass(GoodsClass GoodsClass) {
        return goodsClassMapper.insert(GoodsClass);
    }

    @Override
    public int updateGoodsClass(GoodsClass GoodsClass) {
        return goodsClassMapper.updateByPrimaryKeySelective(GoodsClass);
    }

    @Override
    public int moveGoodsClass(int classiId, int parentClassId) {
        return 0;
    }

    @Override
    public GoodsClass queryGoodsClassById(int classId) {
        return goodsClassMapper.selectByPrimaryKey(classId);
    }

    @Override
    public List<GoodsClass> queryChildrenByClassId(int classId) {
        return goodsClassMapper.selectChildrenById(classId);
    }

    @Override
    public List<Goods> queryGoodsListByClassId(int classId) {
        return goodsMapper.selectGoodsListByClassId(classId);
    }

    @Override
    public int addGoods(Goods goods) {

        goods.setGoodsType("1");    // 默认田1-袋装

        String datetemp = DateUtil.getNowDate();
        goods.setCreateDate(datetemp.substring(0, 8));
        goods.setCreateTime(datetemp.substring(8, 14));
        goods.setUpdateDate(datetemp.substring(0, 8));
        goods.setUpdateTime(datetemp.substring(8, 14));

        return goodsMapper.insertSelective(goods);
    }

    @Override
    public Goods queryGoodsById(int goodsId) {
        return goodsMapper.selectByPrimaryKey(goodsId);
    }

    @Override
    public int updateGoods(Goods goods) {

        String datetemp = DateUtil.getNowDate();
        goods.setUpdateDate(datetemp.substring(0, 8));
        goods.setUpdateTime(datetemp.substring(8, 14));

        return goodsMapper.updateByPrimaryKeySelective(goods);
    }

/*    @Override
    public List<Goods> queryGoodsList(Map<String, Object> parMap) {
        return goodsMapper.selectGoodsList(parMap);
    }*/
}
